# !/usr/bin/env python
# -*- coding: utf-8 -*-
"""
@Time        : 2021/9/18 11:46
@Author      : Albert Darren
@Contact     : 2563491540@qq.com
@File        : scikit_img_downsample.py
@Version     : Version 1.0.0
@Description : TODO
@Created By  : PyCharm
"""
from matplotlib import pyplot as plt
from skimage import io, transform

im = io.imread("./../experiment_fig/aio.jpg")
plt.subplots_adjust(hspace=0.5)


def contrast_show(img, scale_ls, anti_alias=None):
    """
    对比显示不同下采样尺度的图像
    :param img:原始图像
    :param scale_ls:下采样尺度列表
    :param anti_alias:是否抗混叠
    """
    plt.subplot(2, 2, 1)
    plt.title("origin_img")
    plt.imshow(img)
    for index in range(2, len(scale_ls) + 2):
        scale = scale_ls[index - 2]
        plt.subplot(2, 2, index)
        plt.title("scale=" + str(scale))
        # rescale的scale参数的行数和列数与原始图像相反
        rescale_im = transform.rescale(img, (scale, scale, 1), anti_aliasing=anti_alias)
        plt.imshow(rescale_im)
    plt.savefig("./../experiment_fig/" + str(anti_alias) + ".jpg")
    plt.show()


# 使用ANTIALIAS
contrast_show(im, [1 / 2, 1 / 4, 1 / 8], anti_alias=True)
# 不使用ANTIALIAS
# contrast_show(im, [1 / 2, 1 / 4, 1 / 8])
